<template>
	<view class="container">
		<view class="search">
			<image src="../../static/search.png" style="width: 50rpx; height: 50rpx;"></image>
			<input placeholder="请输入搜索内容" v-model="searchText" />
			<view @click="search" style="margin-left: 180rpx;">搜索</view>
		</view>

		<swiper class="swiper" indicator-dots autoplay interval="3000" duration="500">
			<swiper-item v-for="(item,index) in $global.swiper" class="s-item">
				<image class="image" :src="item" mode="aspectFill"></image>
			</swiper-item>
		</swiper>
		<view class="entry-list">
			<navigator class="entry-item" url="/pages/Home/FindLover">
				<image src="/static/rank.png" class="entry-icon"></image>
				<text class="entry-text">匹配</text>
			</navigator>
		</view>
		<view class="recommend">
			<text class="recommend-title">近期明星</text>
			<view class="recommend-list">
				<view class="recommend-item" v-for="item in recommendList" :key="item.id">
					<image :src="item.imgurl" class="recommend-image" mode="aspectFill"></image>
					<text class="recommend-name">{{ item.username }}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import config from '../../common/config';
	export default {
		data() {
			return {
				searchText: '',
				recommendList: [{
					id: 1,
					username: '小美',
					imgurl: '/static/小美.jpg'
				}]
			}
		},
		methods: {
			search() {
				uni.navigateTo({
					url: 'Search?context=' + this.searchText
				})
			},
			onLoad() {

				uni.request({
					url: config.baseUrl + 'person/getActivity',
					method: 'POST',
					data: {

					},
					success: (res) => {
						if (!this.$global.swiper.includes(res.data[0].url)) {
							for (let i = 0; i < res.data.length; i++) {
								res.data[i].url = config.baseUrl + res.data[i].url
								this.$global.swiper.push(res.data[i].url)
							}
						}
						console.log(this.$global.swiper);
					}
				})
				this.recommend()
				this.openid = this.$global.personInfo.openid
				let that = this
				uni.request({
					url: config.baseUrl + 'user/getUserInfo',
					method: 'POST',
					data: {
						"openid": that.openid
					},
					success: (res) => {
						// console.log(res);
						if (res != null || res != 'undefined') {
							that.$global.personInfo = res.data.data
						}
						// console.log(that.$global.personInfo);
					}
				})

			},
			recommend() {
				let that = this
				uni.request({
					url: config.baseUrl + 'home/recommend',
					method: 'GET',
					success: (res) => {
						// console.log(res);
						for (let i = 0; i < res.data.length; i++) {
							res.data[i].imgurl = config.baseUrl + res.data[i].imgurl
						}
						// console.log(res);
						that.recommendList = res.data
						// console.log(that.recommendList);
					}
				})
			},
			navigateTo(page) {
				uni.navigateTo({
					url: '/pages/' + page + '/' + page
				});
			},
		}
	}
</script>

<style scoped>
	.container {
		display: flex;
		flex-direction: column;
		align-items: center;
		background: linear-gradient(to bottom, #FFDAB9, #FFF8DC);
		/* 从上往下变淡的橘色渐变 */
		background: linear-gradient(to right, #FFDAB9, #FFF8DC);
		/* 从左往右变淡的橘色渐变 */
	}

	.search {
		margin-top: 10rpx;
		display: flex;
		flex-direction: row;
		width: 90%;
		border: #bfbfbf solid 5rpx;
		border-radius: 20rpx;
	}

	.title {
		font-size: 24px;
		color: #fff;
	}

	.swiper {
		width: 98%;
		height: 300px;
		margin-top: 20rpx;
		border-radius: 35rpx;
	}

	.entry-list {
		width: 100%;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around;
		margin-top: 20px;
	}

	.entry-item {
		width: 25%;
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-bottom: 20px;
	}

	.image {
		width: 100%;
		height: 100%;
		border-radius: 35rpx;
	}

	.entry-icon {
		width: 50px;
		height: 50px;
	}

	.entry-text {
		margin-top: 5px;
	}

	.recommend {
		width: 95%;
		padding: 5px;
		border: 1rpx solid #bfbfbf;
		margin-bottom: 10rpx;
		border-radius: 15rpx;
	}

	.recommend-title {
		font-size: 18px;
		font-weight: bold;
		/* margin-bottom: 10px; */
	}

	.recommend-list {
		margin-top: 30rpx;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around;
	}

	.recommend-item {
		width: 45%;
		margin-bottom: 20px;
	}

	.recommend-image {
		width: 100%;
		height: 200px;
		object-fit: cover;
		border-radius: 35rpx;
	}

	.recommend-name {
		margin-top: 5px;
		text-align: center;
	}
</style>